package com.duobaoyu.dby.supply.biz.client.resource.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.duobaoyu.dby.common.core.constant.SecurityConstants;
import com.duobaoyu.dby.common.core.constant.ServiceNameConstants;
import com.duobaoyu.dby.common.core.util.R;
import com.duobaoyu.dby.resource.admin.feign.RemoteResourceChannelRuleConfigAdminService;
import com.duobaoyu.dby.resource.common.admin.dto.config.ChannelRuleConfigDTO;
import com.duobaoyu.dby.resource.common.admin.dto.config.ChannelRuleConfigQueryDTO;
import com.duobaoyu.dby.resource.common.admin.dto.config.ScriptDebugDTO;
import com.duobaoyu.dby.resource.common.admin.to.config.ChannelRuleConfigTO;
import com.duobaoyu.dby.supply.biz.client.resource.ResourceChannelRuleConfigAdminClient;
import com.duobaoyu.dby.supply.biz.client.resource.bean.dto.ChannelRuleConfigBizDTO;
import com.duobaoyu.dby.supply.biz.client.resource.bean.dto.ChannelRuleConfigQueryBizDTO;
import com.duobaoyu.dby.supply.biz.client.resource.bean.dto.ScriptDebugBizDTO;
import com.duobaoyu.dby.supply.biz.client.resource.bean.vo.ChannelRuleConfigVO;
import com.duobaoyu.dby.supply.biz.client.resource.converter.ResourceConverter;
import com.duobaoyu.dby.supply.biz.util.RemoteResultCheckUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author liyang
 * @version 1.0.0
 * @ClassName ResourceChannelRuleConfigAdminClientImpl
 * @createTime 13:55:00 2023/10/08
 */
@Component
@RequiredArgsConstructor
public class ResourceChannelRuleConfigAdminClientImpl implements ResourceChannelRuleConfigAdminClient {

    private final ResourceConverter resourceConverter;
    private final RemoteResourceChannelRuleConfigAdminService remoteResourceChannelRuleConfigAdminService;


    @Override
    public boolean createRuleConfig(ChannelRuleConfigBizDTO channelRuleConfig) {
        ChannelRuleConfigDTO dto = resourceConverter.toChannelRuleConfig(channelRuleConfig);
        R<Boolean> result = remoteResourceChannelRuleConfigAdminService.createRuleConfig(dto, SecurityConstants.FROM_IN);
        RemoteResultCheckUtil.checkRemoteResult(result, ServiceNameConstants.RESOURCE_SERVICE, channelRuleConfig);
        return result.getData();
    }

    @Override
    public boolean updateRuleConfig(ChannelRuleConfigBizDTO channelRuleConfig) {
        ChannelRuleConfigDTO dto = resourceConverter.toChannelRuleConfig(channelRuleConfig);
        R<Boolean> result = remoteResourceChannelRuleConfigAdminService.updateRuleConfig(dto, SecurityConstants.FROM_IN);
        RemoteResultCheckUtil.checkRemoteResult(result, ServiceNameConstants.RESOURCE_SERVICE, channelRuleConfig);
        return result.getData();
    }

    @Override
    public boolean deleteRuleConfig(List<Long> channelRuleConfigIds) {
        R<Boolean> result = remoteResourceChannelRuleConfigAdminService.deleteRuleConfig(channelRuleConfigIds, SecurityConstants.FROM_IN);
        RemoteResultCheckUtil.checkRemoteResult(result, ServiceNameConstants.RESOURCE_SERVICE, channelRuleConfigIds);
        return result.getData();
    }

    @Override
    public Page<ChannelRuleConfigVO> channelRuleConfigPage(ChannelRuleConfigQueryBizDTO channelRuleConfig) {
        ChannelRuleConfigQueryDTO dto = resourceConverter.toChannelRuleConfig(channelRuleConfig);
        R<Page<ChannelRuleConfigTO>> result = remoteResourceChannelRuleConfigAdminService.page(dto, SecurityConstants.FROM_IN);
        RemoteResultCheckUtil.checkRemoteResult(result, ServiceNameConstants.RESOURCE_SERVICE, channelRuleConfig);
        return resourceConverter.toChannelRuleConfigPage(result.getData());
    }

    @Override
    public Object scriptDebug(ScriptDebugBizDTO scriptDebug) {
        ScriptDebugDTO dto = resourceConverter.toScriptDebug(scriptDebug);
        R<Object> result = remoteResourceChannelRuleConfigAdminService.scriptDebug(dto, SecurityConstants.FROM_IN);
        RemoteResultCheckUtil.checkRemoteResult(result, ServiceNameConstants.RESOURCE_SERVICE, scriptDebug);
        return result.getData();
    }


}
